package dfbz.com.controller.View;

import dfbz.com.controller.BaseServlet;
import dfbz.com.service.UserService;
import dfbz.com.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/view/*")
public class UIServlet extends BaseServlet {

    private UserService userService = new UserServiceImpl();

    public void index (HttpServletRequest req, HttpServletResponse resp){

        try {
            req.getRequestDispatcher("/index.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void home (HttpServletRequest req, HttpServletResponse resp){
        try {
            Object obj = req.getSession().getAttribute("userId");
            if (null != obj) {
                Integer userId = Integer.parseInt(obj.toString());
                Map<String, Object> map = userService.findUserBaseById(userId);
                req.setAttribute("userBaseInfo", map);
            }
            req.getRequestDispatcher("/html/home.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void showRegister (HttpServletRequest req, HttpServletResponse resp){

        try {
            req.getRequestDispatcher("/register.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void forget (HttpServletRequest req,HttpServletResponse resp) {

        try {
            req.getRequestDispatcher("/forget.jsp").forward(req,resp);
        }catch (Exception e){
            e.printStackTrace();
        }
    }


}
